﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VehicleScale.Models;

namespace VehicleScale.EntityMappers
{
    public class VehicleScaleMapper
    {
        #region Methods With Relation
        public static VehicleScaleModel ToModel(VehicleScale entity)
        {
            if (entity == null) return null;

            VehicleScaleModel model = new VehicleScaleModel()
            {
                VehicleScaleID = entity.VehicleScaleID,
                CustomerID = entity.CustomerID,
                EmployeeID = entity.EmployeeID,
                ProductID = entity.ProductID,
                Customer = CustomerMapper.ToModel(entity.Customer, 0),
                Employee = EmployeeMapper.ToModel(entity.Employee, 0),
                Product = ProductMapper.ToModel(entity.Product, 0),
                ImExType = entity.ImExType,
                ScaleDate = entity.ScaleDate,
                TotalFirstWeight = entity.TotalFirstWeight,
                TotalSecondWeight = entity.TotalSecondWeight,
                CreatedByID = entity.CreatedByID,
                CreationDate = entity.CreationDate,
                ModifiedByID = entity.ModifiedByID,
                ModifiedDate = entity.ModifiedDate,
                Active = entity.Active
            };

            return model;
        }

        public static VehicleScale ToEntity(VehicleScale entity, VehicleScaleModel model)
        {
            if (model == null) return null;

            entity.VehicleScaleID = model.VehicleScaleID;
            entity.CustomerID = model.CustomerID;
            entity.EmployeeID = model.EmployeeID;
            entity.ProductID = model.ProductID;
            entity.ImExType = model.ImExType;
            entity.ScaleDate = model.ScaleDate;
            entity.TotalFirstWeight = model.TotalFirstWeight;
            entity.TotalSecondWeight = model.TotalSecondWeight;
            entity.CreatedByID = model.CreatedByID;
            entity.CreationDate = model.CreationDate;
            entity.ModifiedByID = model.ModifiedByID;
            entity.ModifiedDate = model.ModifiedDate;
            entity.Active = model.Active;

            return entity;
        } 
        #endregion

        #region Methods Without Relation
        public static VehicleScaleModel ToModel(VehicleScale entity, int childLevel)
        {
            if (entity == null) return null;

            VehicleScaleModel model = new VehicleScaleModel()
            {
                VehicleScaleID = entity.VehicleScaleID,
                CustomerID = entity.CustomerID,
                EmployeeID = entity.EmployeeID,
                ProductID = entity.ProductID,
                Customer = CustomerMapper.ToModel(entity.Customer, 0),
                Employee = EmployeeMapper.ToModel(entity.Employee, 0),
                Product = ProductMapper.ToModel(entity.Product, 0),
                ImExType = entity.ImExType,
                ScaleDate = entity.ScaleDate,
                TotalFirstWeight = entity.TotalFirstWeight,
                TotalSecondWeight = entity.TotalSecondWeight,
                CreatedByID = entity.CreatedByID,
                CreationDate = entity.CreationDate,
                ModifiedByID = entity.ModifiedByID,
                ModifiedDate = entity.ModifiedDate,
                Active = entity.Active
            };
            if (childLevel > 0)
            {
                model.VehicleScaleDetails = new List<VehicleScaleDetailModel>();
                foreach (var item in entity.VehicleScaleDetails)
                {
                    model.VehicleScaleDetails.Add(VehicleScaleDetailMapper.ToModel(item));
                }

                model.VehicleScaleSplits = new List<VehicleScaleSplitModel>();
                foreach (var item in entity.VehicleScaleSplits)
                {
                    model.VehicleScaleSplits.Add(VehicleScaleSplitMapper.ToModel(item));
                }
            }

            return model;
        }

        #endregion
    }
}
